package study.dada;

import java.util.Scanner;

public class Rental {
    public static void main(String[] args) {

        System.out.println("欢迎使用答答租车系统:");

        System.out.println("您是否要租车:1是 0否");

        boolean withDraw2 = true,withDraw3 = true,withDraw4 = true;

        Scanner strRent = new Scanner(System.in); //第1次输入，是否租车

        if(strRent.hasNext()){

            String Rent = strRent.nextLine();

//System.out.println(Rent);

            if(Rent.equals("1")){

                System.out.println("您可租车的类型及其价目表:");

                System.out.println("序号    汽车名称        租金         容量");

                System.out.println("1.   奥迪A4       500元/天   载人:4人");//载人 1-4人，2-4人，3-4人，4-20人

                System.out.println("2.   马自达6   400元/天   载人:4人");//载货 3-2吨，5-4吨，6-20吨

                System.out.println("3.   皮卡雪6      450元/天    载人:4 载货:2吨");

                System.out.println("4.   金龙   800元/天   载人:20人");

                System.out.println("5.   松花江            400元/天   载货:4吨");

                System.out.println("6.   依维柯            1000元/天 载货:20吨");

                System.out.println("请输入您要租汽车的数量:");

// System.out.println("您可租车的类型及其价目表:");

//        System.out.println("序号\t汽车名称\t租金\t容量");

//        System.out.println("1.奥迪A4\t500元/天\t载人:4人");//载人 1-4人，2-4人，3-4人，4-20人

//        System.out.println("2.马自达6\t400元/天\t载人:4人");//载货 3-2吨，5-4吨，6-20吨

//        System.out.println("3.皮卡雪6\t450元/天\t载人:4 载货:2吨");

//        System.out.println("4.金龙\t800元/天\t载人:20人");

//        System.out.println("5.松花江\t400元/天\t载货:4吨");

//        System.out.println("6.依维柯\t1000元/天\t载货:20吨");

//        System.out.println("请输入您要租汽车的数量:");

                Rent = null;

                Scanner strRentNumber = new Scanner(System.in); //第2次输入，租几辆

                if(strRentNumber.hasNext()){

                    String RentNumber = strRentNumber.nextLine();

                    for (int i = 0; i < RentNumber.length(); i++){

                        if(withDraw2 == true){

                            if (!Character.isDigit(RentNumber.charAt(i))){

                                System.out.println("非法输入!");

                                withDraw2 = false;

                                break;

                            }

                        }else{break;}

                    }

                    if(withDraw2 == true){

                        int rentNumber = Integer.parseInt(RentNumber);

                        int[] rentCar = new int[rentNumber + 1];

                        for(int i = 0; i<rentNumber+1;i++){

                            rentCar[i] = 0;

                        }

                        int j = 1,i = 1;

                        while(j <= rentNumber){

                            if(withDraw3 == true){

                                System.out.println("请输入第"+j+"辆车的序号:");

                                Scanner strCarType = new Scanner(System.in);//第3次输入，租哪辆车

                                if(strCarType.hasNext()){

                                    String CarType = strCarType.nextLine();

                                    for (i = 0; i < CarType.length(); i++){

                                        if (!Character.isDigit(CarType.charAt(i))){

                                            System.out.println("非法输入!");

                                            withDraw3 = false;

                                            break;

                                        }

                                    }

                                    if(withDraw3 == true){

                                        int carType = Integer.parseInt(CarType);

                                        rentCar[j] = carType;

                                        if(rentCar[j] < 1 || rentCar[j] > 6)

                                        {

                                            System.out.println("非法输入!");

                                            System.out.println( "没有" + rentCar[j] + "型车。");

                                            System.out.println("再见!");

                                            withDraw3 = false;

                                        }

                                    }

                                }



                            }else{break;}

                            j++;

                        }

                        if(withDraw3 == true){

                            double cost = 0.0,load = 0.0;

                            int manned = 0;

                            for(i = 1; i <= rentNumber;i++){

                                if(rentCar[i] > 0){

                                    switch (rentCar[i]){

                                        case 0:break;

                                        case 1:cost += 500;manned += 4;break;

                                        case 2:cost += 400;manned += 4;break;

                                        case 3:cost += 450;manned += 4;load += 2;break;

                                        case 4:cost += 800;manned += 20;break;

                                        case 5:cost += 400;load += 4;break;

                                        case 6:cost += 1000;load += 20;break;

                                        default:break;

                                    }

                                }

                            }

                            System.out.println("请输入租车天数:");//第4次输入，租车天数

                            Scanner strDays = new Scanner(System.in);

                            if(strDays.hasNext()){

                                String RentDays = strDays.nextLine();

                                for ( i = 0; i < RentDays.length(); i++){

                                    if (!Character.isDigit(RentDays.charAt(i))){

                                        System.out.println("非法输入!");

                                        withDraw4 = false;

                                        break;

                                    }

                                }

                                if(withDraw4 == true){

                                    int rentDays = Integer.parseInt(RentDays);

                                    cost *= rentDays;

                                }

                            }

                            if(withDraw4 == true){

                                System.out.println("您的账单:");

                                System.out.println("**可载人的车有:");

                                if(manned == 0){

                                    System.out.println("无");

                                }

                                else{

                                    for(i = 1;i <= rentNumber;i++){

                                        if(rentCar[i] > 0){

                                            if (rentCar[i] == 1||rentCar[i] == 2||rentCar[i] == 3||rentCar[i] == 4){

                                                switch(rentCar[i]){

                                                    case 1:System.out.print("奥迪A4" + " ");break;

                                                    case 2:System.out.print("马自达6" + " ");break;

                                                    case 3:System.out.print("皮卡雪6" + " ");break;

                                                    case 4:System.out.print("金龙" + " ");break;

                                                    default:break;

                                                }

                                            }

                                        }

                                    }

                                }

                                System.out.println("共载人:" + manned);

                                System.out.println("**载货的车有:");

                                if(load == 0){

                                    System.out.println("无");

                                }

                                else{

                                    for(i = 1;i <= rentNumber;i++){

                                        if(rentCar[i] > 0){

                                            if (rentCar[i] == 3||rentCar[i] == 5||rentCar[i] == 6){

                                                switch(rentCar[i]){

                                                    case 3:System.out.print("皮卡雪6" + " ");break;

                                                    case 5:System.out.print("松花江" + " ");break;

                                                    case 6:System.out.print("依维河" + " ");break;

                                                    default:break;

                                                }

                                            }

                                        }

                                    }

                                }

                                System.out.println("共载货:" + load + "吨");

                                System.out.println("**租车总价格:" + cost +"元");

                                System.out.println("账单计算结束.感谢您的光临,祝您生活愉快!");

                            }

                        }

                    }

                }

            }else if(Rent.equals("0"))

            {

                System.out.println("ByeBye!");

            }else{

                System.out.println("非法输入!再见!");

            }

        }

    }

}